<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>代码生成</title>
    <link rel="stylesheet" href="../layui/css/layui.css">
</head>
<body class="layui-layout-body ">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">代码生成</div>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree"  lay-filter="test">
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="javascript:;">控制台</a>
                </li>
            </ul>
        </div>
    </div>

    <div class="layui-body">
        <div>
            <label class="layui-form-label"></label>
        </div>
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">项目名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="projectName" required  lay-verify="required" placeholder="请输入项目名称(英文)" autocomplete="off" class="layui-input">
                    </div>

                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">作者</label>
                    <div class="layui-input-block">
                        <input type="text" name="author"  placeholder="作者" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">项目描述</label>
                <div class="layui-input-block">
                    <input type="text" name="projectComment"  placeholder="项目描述(中文英文都可以)" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">项目包路径</label>
                <div class="layui-input-block">
                    <input type="text" name="pPackage" required  lay-verify="required" placeholder="com.xxx.demo" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">项目根路径</label>
                <div class="layui-input-block">
                    <input type="text" name="outPath" required  lay-verify="required" placeholder="D:\MyProjectRootPath" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">数据库名称</label>
                <div class="layui-input-block">
                    <input type="text" name="db" required  lay-verify="required" placeholder="数据库名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">数据库ip</label>
                    <div class="layui-input-block">
                        <input type="text" name="ip" required  lay-verify="required" placeholder="数据库ip" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">数据库端口</label>
                    <div class="layui-input-block">
                        <input type="text" name="port" required  lay-verify="required" placeholder="数据库端口" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">数据库账号</label>
                    <div class="layui-input-block">
                        <input type="text" name="username" required  lay-verify="required" placeholder="数据库连接名" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">数据库密码</label>
                    <div class="layui-input-inline">
                        <input type="password" name="password" required lay-verify="required" placeholder="数据库密码" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">数据库类型</label>
                <div class="layui-input-block">
                    <input type="radio" name="dataBaseType" value="mysql" title="mysql" checked>
                    <input type="radio" name="dataBaseType" value="oracle" title="oracle" disabled>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">模板类型</label>
                <div class="layui-input-block">
                    <input type="radio" name="templateType" value="1" title="前端" disabled>
                    <input type="radio" name="templateType" value="2" title="后端" disabled>
                    <input type="radio" name="templateType" value="0" title="全部" checked>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formDemo">立即生成</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>

    <div class="layui-footer">
        <!-- 底部固定区域 -->
        © layui.com - 底部固定区域
    </div>
</div>

<script src="../layui/layui.js"></script>
<script>
    layui.use('form', function(){
        var $ = layui.jquery;
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function(data){
            //layer.msg(JSON.stringify(data.field));

            $.ajax({
                type: 'post',
                url: '/code/generation',
                dataType:'json',
                data:JSON.stringify(data.field),
                contentType: "application/json; charset=utf-8",
                beforeSend:function(){
                    i = showLoad();
                },
                success:function(res){//res为相应体,function为回调函数

                    if(res.status==200){
                        closeLoad(i);
                        layer.msg("代码生成成功!", {icon: 6,time: 1000});
                    }else{
                        closeLoad(i);
                        layer.alert(res.message,{icon: 5});
                    }
                },
                error:function(res){
                    closeLoad(i);
                    layer.alert(res.responseJSON.message,{icon:5});
                }
            });
            return false;
        });
    });

    // 等待
    function showLoad() {
        return layer.msg('拼命执行中...', {icon: 16,shade: [0.5, '#f5f5f5'],scrollbar: false,offset: 'auto', time:100000});
    }

    // 关闭
    function closeLoad(index) {
        layer.close(index);
    }

</script>
</body>
</html>